package Fragment

import android.annotation.SuppressLint
import android.app.AlertDialog
import android.content.Context
import android.content.DialogInterface
import android.graphics.Color
import android.os.Bundle
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.PopupWindow
import android.widget.SearchView
import android.widget.TextView
import androidx.fragment.app.Fragment
import com.bigkoo.pickerview.TimePickerView
import com.example.hospitalmanagementapp.R
import com.lljjcoder.Interface.OnCityItemClickListener
import com.lljjcoder.bean.CityBean
import com.lljjcoder.bean.DistrictBean
import com.lljjcoder.bean.ProvinceBean
import com.lljjcoder.citywheel.CityConfig
import com.lljjcoder.style.citypickerview.CityPickerView
import kotlinx.android.synthetic.main.fragment_people__child.*
import util.DocumentTypeUtil
import util.RegionalSelectedUtil
import util.TimeSelectedUtil
import java.text.SimpleDateFormat
import java.util.*

class PeopleChildFragment(context: Context) : Fragment() {
    private val context1:Context=context
    var  array= arrayOf("身份证","护照","港澳居民来往内地通行证",
        "台湾居民来往内地通行证","外国人永久居留身份证","中华人民共和国出入境通行证","中华人民共和国旅行证")
    private var mPopupWindow = PopupWindow()
    private val timeSelectedUtil=TimeSelectedUtil(context)

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        return inflater.inflate(R.layout.fragment_people__child, container, false)
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        initView()
    }
//初始化
    private fun initView() {
    //省市县选择实现
    // 初始化城市选择器
    regional_choose.setOnClickListener {
   var cityPickerView =RegionalSelectedUtil(context1).regionalSelect()
        cityPickerView.setOnCityItemClickListener(object : OnCityItemClickListener() {
            @SuppressLint("SetTextI18n")
            override fun onSelected(
                province: ProvinceBean,
                city: CityBean,
                district: DistrictBean
            ) {
                super.onSelected(province, city, district);
                     regional_choose.setText(
                    province.toString().trim()  + city.toString()
                        .trim()  + district.toString().trim()
                );
            }
        })


    }

    id_category.setOnClickListener {
        //身份证功能实现
     var documentSelect=DocumentTypeUtil(context1).documentType()
        documentSelect.setItems(array, DialogInterface.OnClickListener { dialog, which ->
            id_category.setText(array[which])
        })
    }

    //日期选择实现
   val pickerView=timeSelectedUtil.timeSelected()
    time_picker_view.setOnClickListener {
     pickerView.show(time_picker_view)
    }
    //照相机功能实现
    camera_btn.setOnClickListener {
        showPopupWindow()
    }

}
//照相机功能
        private fun showPopupWindow() {
//设置ContentView
            val contentView = LayoutInflater.from(context).inflate(R.layout.camara_item, null)
            mPopupWindow = PopupWindow(
                contentView, ViewGroup.LayoutParams.WRAP_CONTENT,
                ViewGroup.LayoutParams.WRAP_CONTENT, true
            )
            mPopupWindow.contentView
            // 显示popupWindow
            val rootView =
                LayoutInflater.from(context).inflate(R.layout.fragment_people__child, null)
            mPopupWindow.showAtLocation(rootView, Gravity.LEFT, 0, 0)
        }
    }